/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[欢迎加盟知启蒙，一起邂逅框架梦]
 * 
 * https://www.zhiqim.com/gitcan/zhiqim/zhiqim_account.htm
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.zhiqim.account.api.connect;

import org.zhiqim.kernel.json.Jsons;

public class QQUserInfo implements IUserInfo
{
    private String json;
    private String openId;
    
    private String nickName;                    //nickname  用户在QQ空间的昵称。 
    private String figureUrl30x30;              //figureurl    大小为30×30像素的QQ空间头像URL。 
    private String figureUrl50x50;              //figureurl_1     大小为50×50像素的QQ空间头像URL。 
    private String figureUrl100x100;            //figureurl_2  大小为100×100像素的QQ空间头像URL。 
    private String figureUrlQQ40x40;            //figureurl_qq_1  大小为40×40像素的QQ头像URL。 
    private String figureUrlQQ100x100;          //figureurl_qq_2  大小为100×100像素的QQ头像URL。需要注意，不是所有的用户都拥有QQ的100x100的头像，但40x40像素则是一定会有。
    private String gender;                      //gender  性别。 如果获取不到则默认返回"男" 
    private boolean isYellowVip;                //is_yellow_vip   标识用户是否为黄钻用户（0：不是；1：是）。
    private boolean isVip;                      //vip     标识用户是否为黄钻用户（0：不是；1：是） 
    private int yellowVipLevel;                 //yellow_vip_level    黄钻等级
    private int level;                          //level   黄钻等级
    private boolean isYellowYearVip;            //is_yellow_year_vip  标识是否为年费黄钻用户（0：不是； 1：是） 
    
    public QQUserInfo parse(String json)
    {
        this.json = json;
        
        this.nickName = Jsons.getString(json, "nickname");
        this.figureUrl30x30 = Jsons.getString(json, "figureurl");
        this.figureUrl50x50 = Jsons.getString(json, "figureurl_1");
        this.figureUrl100x100 = Jsons.getString(json, "figureurl_2");
        this.figureUrlQQ40x40 = Jsons.getString(json, "figureurl_qq_1");
        this.figureUrlQQ100x100 = Jsons.getString(json, "figureurl_qq_2");
        this.gender = Jsons.getString(json, "gender");
        this.isYellowVip = Jsons.getInt(json, "is_yellow_vip") == 1;
        this.isVip = Jsons.getInt(json, "vip") == 1;
        this.yellowVipLevel = Jsons.getInt(json, "yellowVipLevel");
        this.level = Jsons.getInt(json, "level");
        this.isYellowYearVip = Jsons.getInt(json, "is_yellow_year_vip") == 1;
        
        return this;
    }

    public String getNickName()
    {
        return nickName;
    }

    public String getFigureUrl30x30()
    {
        return figureUrl30x30;
    }
    
    public String getFigureUrl50x50()
    {
        return figureUrl50x50;
    }

    public String getFigureUrl100x100()
    {
        return figureUrl100x100;
    }

    public String getFigureUrlQQ40x40()
    {
        return figureUrlQQ40x40;
    }

    public String getFigureUrlQQ100x100()
    {
        return figureUrlQQ100x100;
    }

    public String getGender()
    {
        return gender;
    }

    public boolean isYellowVip()
    {
        return isYellowVip;
    }

    public boolean isVip()
    {
        return isVip;
    }

    public int getYellowVipLevel()
    {
        return yellowVipLevel;
    }

    public int getLevel()
    {
        return level;
    }

    public boolean isYellowYearVip()
    {
        return isYellowYearVip;
    }
    
    public String toString()
    {
        return json;
    }
    
    public String getOpenId()
    {
        return openId;
    }

    public QQUserInfo setOpenId(String openId)
    {
        this.openId = openId;
        return this;
    }
    
    /*************************************************************************************/
    //实现IUserInfo接口
    /*************************************************************************************/
    
    @Override
    public int getAccountType()
    {
        return ACCOUNT_TYPE_QQ;
    }
    
    @Override
    public String getAccountUnion()
    {
        return null;
    }

    @Override
    public String getUserAccount()
    {
        return openId;
    }
    
    @Override
    public String getUserNick()
    {
        return nickName;
    }
    
    @Override
    public int getUserSex()
    {
        return "女".equals(gender)?2:"男".equals(gender)?1:0;
    }

    @Override
    public String getUserAvatar50()
    {
        return figureUrlQQ40x40;
    }
    
    @Override
    public String getUserAvatar100()
    {
        return figureUrlQQ100x100;
    }

    @Override
    public String getUserAvatar150()
    {
        return figureUrlQQ100x100;
    }
}
